#include <audio_process.h>
#include "smbPitchShift.h"

audio_process::audio_process()
{
}

int audio_process::process(AVFrame* frame,int rate)
{   

    //void smbPitchShift(float pitchShift, long numSampsToProcess, long fftFrameSize, long osamp, float sampleRate, float     *indata, float *outdata);
    long semitones = 6;                         // shift up by 8 semitones
    float pitchShift = pow(2., semitones/12.);  // convert semitones to factor   

     if(frame->format == AV_SAMPLE_FMT_FLTP)
     {        
        float * p_left_data = (float*)frame->data[0];   

        // FILE * p = fopen("./test.pcm","ab");
        // if(p) {
        //     fwrite(p_left_data,1024,4,p);
        //     fclose(p);
        // }   
         
        smbPitchShift(pitchShift, 1024, 1024, 4, rate, p_left_data,p_left_data);

        float * p_right_data = (float*)frame->data[1];
        //smbPitchShift(pitchShift, 1024, 1024, 4, rate, p_right_data,p_right_data);
        mempcpy(p_right_data,p_left_data,4096);
        
     } 
    return 0;
}
